package com.appbee.core.client.upload;

import com.google.gwt.core.client.JavaScriptObject;

public class FileReader extends JavaScriptObject
{
	protected FileReader(){}
	
	public final native static FileReader create()/*-{
		return new FileReader();
	}-*/;
	
	/**
	 * When the read has successfully completed. 
	 * @param handler
	 */
	public final native void setLoadListener(LoadListener handler)/*-{
																	this.onload = $entry(function(e) {
																	handler.@com.appbee.core.client.upload.LoadListener::onLoad(Lcom/appbee/core/client/upload/ProgressEvent;)(e);
																	});
																	}-*/;

	/**
	 * While reading (and decoding) blob, and reporting partial Blob data (progess.loaded/progress.total) 
	 * @param handler
	 */
	public final native void setProgressListener(ProgressListener handler)/*-{
																			this.onprogress = $entry(function(e) {
																			handler.@com.appbee.core.client.upload.ProgressListener::onProgress(Lcom/appbee/core/client/upload/ProgressEvent;)(e);
																			});
																			}-*/;
	
	/**
	 * When the read starts. 
	 * @param handler
	 */
	public final native void setLoadStartListener(LoadStartListener handler)/*-{
																			this.onloadstart = $entry(function(e) {
																			handler.@com.appbee.core.client.upload.LoadStartListener::onLoadStart(Lcom/appbee/core/client/upload/ProgressEvent;)(e);
																			});
																			}-*/;

	/**
	 * When the request has completed (either in success or failure). 
	 * @param handler
	 */
	public final native void setLoadEndListener(LoadEndListener handler)
	/*-{
		this.onloadend = $entry(function(e) {
		handler.@com.appbee.core.client.upload.LoadEndListener::onLoadEnd(Lcom/appbee/core/client/upload/ProgressEvent;)(e);
		});
	}-*/;

	/**
	 * When the request has completed (either in success or failure). 
	 * @param handler
	 */
	public final native void setErrorListener(ErrorListener handler)/*-{
																	this.onerror = $entry(function(e) {
																	handler.@com.appbee.core.client.upload.ErrorListener::onError(Lcom/appbee/core/client/upload/ProgressEvent;)(e);
																	});
																	}-*/;

	public final native void readAsDataURL(Blob blob)/*-{
		return this.readAsDataURL(blob);
	}-*/;

	public final native void readAsBinaryString(Blob blob)/*-{
		return this.readAsBinaryString(blob);
	}-*/;
}
